﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Ylh.Model;
using Ylh.FactoryDAL;

namespace Ylh.BLL
{
    public class DepartmentBLL
    {
        private string ConStr = string.Empty;

        public DepartmentBLL(string ConStr)
        {
            this.ConStr = ConStr;
        }

        /// <summary>
        /// 插入一条数据,并且放回ID号码
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="model">TbDepartment对象</param>
        /// <returns></returns>
        public int InsertDepartment(TbDepartment model)
        {
            Ylh.IDAL.IDepartment Ide = Ylh.FactoryDAL.DataAccess.CreateIDepartment();
            return Ide.InsertDepartment(ConStr, model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="model">TbDepartment对象</param>
        /// <returns></returns>
        public bool UpdateDepartment(TbDepartment model)
        {
            Ylh.IDAL.IDepartment Ide = Ylh.FactoryDAL.DataAccess.CreateIDepartment();
            return Ide.UpdateDepartment(ConStr, model);
        }


        /// <summary>
        /// 判断部门名称是否存在
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="DeparName">部门名称</param>
        /// <returns></returns>
        public bool IsDeParNameExists(string DeparName)
        {
            Ylh.IDAL.IDepartment Ide = Ylh.FactoryDAL.DataAccess.CreateIDepartment();
            return Ide.IsDeParNameExists(ConStr, DeparName);
        }

        /// <summary>
        /// 判断部门下面是否存在员工
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="DepartmentID">部门编号</param>
        /// <returns></returns>
        public bool IsdeparmentHseStaff(string DepartmentID)
        {
            Ylh.IDAL.IDepartment Ide = Ylh.FactoryDAL.DataAccess.CreateIDepartment();
            return Ide.IsdeparmentHseStaff(ConStr, DepartmentID);
        }
        /// <summary>
        /// 根据部门编号删除部门信息
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="DepartmentID">部门编号</param>
        /// <returns></returns>
        public bool DeleteDepartmentInfo(string DepartmentID)
        {
            Ylh.IDAL.IDepartment Ide = Ylh.FactoryDAL.DataAccess.CreateIDepartment();
            return Ide.DeleteDepartmentInfo(ConStr, DepartmentID);
        }

        /// <summary>
        /// 获取部门信息
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="DepartmentID">部门编号</param>
        /// <returns></returns>
        public DataTable GetDepartMentInfo(decimal DepartmentID)
        {
            Ylh.IDAL.IDepartment Ide = Ylh.FactoryDAL.DataAccess.CreateIDepartment();
            return Ide.GetDepartMentInfo(ConStr, DepartmentID);
        }


        public void DeleteDepartmentInfo(List<string> li)
        {
            foreach (string str in li)
            {
                if (IsdeparmentHseStaff(str))
                {
                    continue;
                }
                DeleteDepartmentInfo(str);
            }
        }

        /// <summary>
        /// 获取服务部门信息
        /// 两个条件同时作用
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="DepartmentID">部门ID,如果为-1则获取所有服务部门的信息</param>
        /// <param name="IsServer">
        /// true 获取服务部门
        /// false 获取非服务部门
        /// null 获取所有部门信息
        /// </param>
        /// <returns></returns>
        public DataTable GetServerDepartMentInfo(decimal DepartmentID, bool? IsServer)
        {
            Ylh.IDAL.IDepartment Ide = DataAccess.CreateIDepartment();
            return Ide.GetServerDepartMentInfo(ConStr, DepartmentID, IsServer);
        }


        /// <summary>
        /// 设置部门的负责人
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="staffID">负责人ID</param>
        /// <param name="DeparmentID">部门编号</param>
        /// <returns></returns>
        public bool SetDeparmentHead(string staffID, string DeparmentID)
        {
            Ylh.IDAL.IDepartment Ide = DataAccess.CreateIDepartment();
            return Ide.SetDeparmentHead(ConStr, staffID, DeparmentID);
        }
    }
}
